<?php
require_once "Zend/Mail.php";

require_once "SPage.php";
require_once "SError.php";
require_once "SNews.php";
require_once "SLogobanner.php";

class AboutController extends Zend_Controller_Action
{
	private $uiVar = array();
	private $sPage;
	private $sNews;
	
	public function init()
	{
		$this->uiVar["html"]["pageTitle"] = WEBSITE_TITLE;
		$this->sPage = new SPage();
		$this->sNews = new SNews();
	}
	
	public function indexAction()
	{
		$pageValues = array();
		$pageValues["data"]["selectedMenu"] = "about";
		$pageValues["data"]["selectedSubMenu"] = "about";
		
		$language = (int)trim($this->_getParam("lang"));
		if ($language == 0)
			$language = 1;
		
		/*********************************************************************/
		$sLogoBanner = new SLogobanner();		
		$pageValues["data"]["leftBanner"]=$bannerLeft = $sLogoBanner->getBanner(1);
		$nameBanner1 = explode(".",$pageValues['data']['leftBanner']['ImagePath']);
		$pageValues["data"]["left_banner_name"] = $nameBanner1[0];

		
		
		$pageValues["data"]["headerBanner"]=$bannerLeft = $sLogoBanner->getBanner(2);
		$nameBanner2 = explode(".",$pageValues['data']['headerBanner']['ImagePath']);
		$pageValues["data"]["header_banner_name"] = $nameBanner2[0];
		
		
		$pageValues["data"]["centerBanner"]=$bannerLeft = $sLogoBanner->getBanner(3);
		$nameBanner3 = explode(".",$pageValues['data']['centerBanner']['ImagePath']);
		$pageValues["data"]["center_banner_name"] = $nameBanner3[0];
		/*********************************************************************/
				
		$pageValues["page"] = $this->sPage->getPage(1, $language);
		$pageValues["news"]["hot"] = $this->sNews->getNewsHotList($language, 0, HOMEPAGE_TOTAL_NEWS_PER_PAGE);
		
		$this->uiVar["pageValues"] = $pageValues;

		$smarty = Zend_Registry::get("SMARTY");
		$smarty->assign("uiVar", $this->uiVar);
		$smarty->display("about_" . $language . ".htm");
	}
	
	public function organizationAction()
	{
		$pageValues = array();
		$pageValues["data"]["selectedMenu"] = "about";
		$pageValues["data"]["selectedSubMenu"] = "organization";
		
		$language = (int)trim($this->_getParam("lang"));
		if ($language == 0)
			$language = 1;
		
		/*********************************************************************/
		$sLogoBanner = new SLogobanner();		
		$pageValues["data"]["leftBanner"]=$bannerLeft = $sLogoBanner->getBanner(1);
		$nameBanner1 = explode(".",$pageValues['data']['leftBanner']['ImagePath']);
		$pageValues["data"]["left_banner_name"] = $nameBanner1[0];

		
		
		$pageValues["data"]["headerBanner"]=$bannerLeft = $sLogoBanner->getBanner(2);
		$nameBanner2 = explode(".",$pageValues['data']['headerBanner']['ImagePath']);
		$pageValues["data"]["header_banner_name"] = $nameBanner2[0];
		
		
		$pageValues["data"]["centerBanner"]=$bannerLeft = $sLogoBanner->getBanner(3);
		$nameBanner3 = explode(".",$pageValues['data']['centerBanner']['ImagePath']);
		$pageValues["data"]["center_banner_name"] = $nameBanner3[0];
		/*********************************************************************/		
		$pageValues["page"] = $this->sPage->getPage(2, $language);
		$pageValues["news"]["hot"] = $this->sNews->getNewsHotList($language, 0, HOMEPAGE_TOTAL_NEWS_PER_PAGE);
		
		$this->uiVar["pageValues"] = $pageValues;

		$smarty = Zend_Registry::get("SMARTY");
		$smarty->assign("uiVar", $this->uiVar);
		$smarty->display("about_organization_" . $language . ".htm");
	}
	
	public function strategyAction()
	{
		$pageValues = array();
		$pageValues["html"]["title"] = WEBSITE_TITLE;
		$pageValues["data"]["selectedMenu"] = "about";
		$pageValues["data"]["selectedSubMenu"] = "strategy";
		
		$language = (int)trim($this->_getParam("lang"));
		if ($language == 0)
			$language = 1;
		/*********************************************************************/
		$sLogoBanner = new SLogobanner();		
		$pageValues["data"]["leftBanner"]=$bannerLeft = $sLogoBanner->getBanner(1);
		$nameBanner1 = explode(".",$pageValues['data']['leftBanner']['ImagePath']);
		$pageValues["data"]["left_banner_name"] = $nameBanner1[0];

		
		
		$pageValues["data"]["headerBanner"]=$bannerLeft = $sLogoBanner->getBanner(2);
		$nameBanner2 = explode(".",$pageValues['data']['headerBanner']['ImagePath']);
		$pageValues["data"]["header_banner_name"] = $nameBanner2[0];
		
		
		$pageValues["data"]["centerBanner"]=$bannerLeft = $sLogoBanner->getBanner(3);
		$nameBanner3 = explode(".",$pageValues['data']['centerBanner']['ImagePath']);
		$pageValues["data"]["center_banner_name"] = $nameBanner3[0];
		/*********************************************************************/		
		$pageValues["page"] = $this->sPage->getPage(3, $language);
		$pageValues["news"]["hot"] = $this->sNews->getNewsHotList($language, 0, HOMEPAGE_TOTAL_NEWS_PER_PAGE);
		
		$this->uiVar["pageValues"] = $pageValues;

		$smarty = Zend_Registry::get("SMARTY");
		$smarty->assign("uiVar", $this->uiVar);
		$smarty->display("about_strategy_" . $language . ".htm");
	}
	
	public function photoAction()
	{
		// Forward to AboutPhotoController for elegant structuring.
		$this->_forward('photo', 'about-photo');
	}
	
	public function infoAction()
	{
		$pageValues = array();
		$pageValues["html"]["title"] = WEBSITE_TITLE;
		$pageValues["data"]["selectedMenu"] = "about";
		$pageValues["data"]["selectedSubMenu"] = "info";
		/*********************************************************************/
		$sLogoBanner = new SLogobanner();		
		$pageValues["data"]["leftBanner"]=$bannerLeft = $sLogoBanner->getBanner(1);
		$nameBanner1 = explode(".",$pageValues['data']['leftBanner']['ImagePath']);
		$pageValues["data"]["left_banner_name"] = $nameBanner1[0];

		
		
		$pageValues["data"]["headerBanner"]=$bannerLeft = $sLogoBanner->getBanner(2);
		$nameBanner2 = explode(".",$pageValues['data']['headerBanner']['ImagePath']);
		$pageValues["data"]["header_banner_name"] = $nameBanner2[0];
		
		
		$pageValues["data"]["centerBanner"]=$bannerLeft = $sLogoBanner->getBanner(3);
		$nameBanner3 = explode(".",$pageValues['data']['centerBanner']['ImagePath']);
		$pageValues["data"]["center_banner_name"] = $nameBanner3[0];
		/*********************************************************************/		
		$pageValues["page"] = $this->sPage->getPage(4, LANGUAGE_VIETNAMESE);
		$pageValues["news"]["hot"] = $this->sNews->getNewsHotList(LANGUAGE_VIETNAMESE, 0, HOMEPAGE_TOTAL_NEWS_PER_PAGE);
		
		$this->uiVar["pageValues"] = $pageValues;

		$smarty = Zend_Registry::get("SMARTY");
		$smarty->assign("uiVar", $this->uiVar);
		$smarty->display("about_info.htm");
	}
	
	public function careerAction()
	{
		$pageValues = array();
		$pageValues["html"]["title"] = WEBSITE_TITLE;
		$pageValues["data"]["selectedMenu"] = "about";
		$pageValues["data"]["selectedSubMenu"] = "career";
		
		$language = (int)trim($this->_getParam("lang"));
		if ($language == 0)
			$language = 1;
		/*********************************************************************/
		$sLogoBanner = new SLogobanner();		
		$pageValues["data"]["leftBanner"]=$bannerLeft = $sLogoBanner->getBanner(1);
		$nameBanner1 = explode(".",$pageValues['data']['leftBanner']['ImagePath']);
		$pageValues["data"]["left_banner_name"] = $nameBanner1[0];

		
		
		$pageValues["data"]["headerBanner"]=$bannerLeft = $sLogoBanner->getBanner(2);
		$nameBanner2 = explode(".",$pageValues['data']['headerBanner']['ImagePath']);
		$pageValues["data"]["header_banner_name"] = $nameBanner2[0];
		
		
		$pageValues["data"]["centerBanner"]=$bannerLeft = $sLogoBanner->getBanner(3);
		$nameBanner3 = explode(".",$pageValues['data']['centerBanner']['ImagePath']);
		$pageValues["data"]["center_banner_name"] = $nameBanner3[0];
		/*********************************************************************/		
		$pageValues["page"] = $this->sPage->getPage(5, $language);
		$pageValues["news"]["hot"] = $this->sNews->getNewsHotList($language, 0, HOMEPAGE_TOTAL_NEWS_PER_PAGE);
		
		$this->uiVar["pageValues"] = $pageValues;

		$smarty = Zend_Registry::get("SMARTY");
		$smarty->assign("uiVar", $this->uiVar);
		$smarty->display("about_career_" . $language . ".htm");
	}
	
	public function sitemapAction()
	{
		$pageValues = array();
		$pageValues["html"]["title"] = WEBSITE_TITLE;
		$pageValues["data"]["selectedMenu"] = "about";
		$pageValues["data"]["selectedSubMenu"] = "sitemap";
		
		$language = (int)trim($this->_getParam("lang"));
		if ($language == 0)
			$language = 1;
		/*********************************************************************/
		$sLogoBanner = new SLogobanner();		
		$pageValues["data"]["leftBanner"]=$bannerLeft = $sLogoBanner->getBanner(1);
		$nameBanner1 = explode(".",$pageValues['data']['leftBanner']['ImagePath']);
		$pageValues["data"]["left_banner_name"] = $nameBanner1[0];

		
		
		$pageValues["data"]["headerBanner"]=$bannerLeft = $sLogoBanner->getBanner(2);
		$nameBanner2 = explode(".",$pageValues['data']['headerBanner']['ImagePath']);
		$pageValues["data"]["header_banner_name"] = $nameBanner2[0];
		
		
		$pageValues["data"]["centerBanner"]=$bannerLeft = $sLogoBanner->getBanner(3);
		$nameBanner3 = explode(".",$pageValues['data']['centerBanner']['ImagePath']);
		$pageValues["data"]["center_banner_name"] = $nameBanner3[0];
		/*********************************************************************/		
		$pageValues["page"] = $this->sPage->getPage(6, $language);
		$pageValues["news"]["hot"] = $this->sNews->getNewsHotList($language, 0, HOMEPAGE_TOTAL_NEWS_PER_PAGE);
		
		$this->uiVar["pageValues"] = $pageValues;

		$smarty = Zend_Registry::get("SMARTY");
		$smarty->assign("uiVar", $this->uiVar);
		$smarty->display("about_sitemap_" . $language . ".htm");
	}
	
	public function tosAction()
	{
		$pageValues = array();
		$pageValues["html"]["title"] = WEBSITE_TITLE;
		$pageValues["data"]["selectedMenu"] = "about";
		$pageValues["data"]["selectedSubMenu"] = "tos";
		/*********************************************************************/
		$sLogoBanner = new SLogobanner();		
		$pageValues["data"]["leftBanner"]=$bannerLeft = $sLogoBanner->getBanner(1);
		$nameBanner1 = explode(".",$pageValues['data']['leftBanner']['ImagePath']);
		$pageValues["data"]["left_banner_name"] = $nameBanner1[0];

		
		
		$pageValues["data"]["headerBanner"]=$bannerLeft = $sLogoBanner->getBanner(2);
		$nameBanner2 = explode(".",$pageValues['data']['headerBanner']['ImagePath']);
		$pageValues["data"]["header_banner_name"] = $nameBanner2[0];
		
		
		$pageValues["data"]["centerBanner"]=$bannerLeft = $sLogoBanner->getBanner(3);
		$nameBanner3 = explode(".",$pageValues['data']['centerBanner']['ImagePath']);
		$pageValues["data"]["center_banner_name"] = $nameBanner3[0];
		/*********************************************************************/		
		$pageValues["page"] = $this->sPage->getPage(51, LANGUAGE_VIETNAMESE);
		$pageValues["news"]["hot"] = $this->sNews->getNewsHotList(LANGUAGE_VIETNAMESE, 0, HOMEPAGE_TOTAL_NEWS_PER_PAGE);
		
		$this->uiVar["pageValues"] = $pageValues;

		$smarty = Zend_Registry::get("SMARTY");
		$smarty->assign("uiVar", $this->uiVar);
		$smarty->display("about_tos.htm");
	}
	
	public function privacyAction()
	{
		$pageValues = array();
		$pageValues["html"]["title"] = WEBSITE_TITLE;
		$pageValues["data"]["selectedMenu"] = "about";
		$pageValues["data"]["selectedSubMenu"] = "privacy";
		/*********************************************************************/
		$sLogoBanner = new SLogobanner();		
		$pageValues["data"]["leftBanner"]=$bannerLeft = $sLogoBanner->getBanner(1);
		$nameBanner1 = explode(".",$pageValues['data']['leftBanner']['ImagePath']);
		$pageValues["data"]["left_banner_name"] = $nameBanner1[0];

		
		
		$pageValues["data"]["headerBanner"]=$bannerLeft = $sLogoBanner->getBanner(2);
		$nameBanner2 = explode(".",$pageValues['data']['headerBanner']['ImagePath']);
		$pageValues["data"]["header_banner_name"] = $nameBanner2[0];
		
		
		$pageValues["data"]["centerBanner"]=$bannerLeft = $sLogoBanner->getBanner(3);
		$nameBanner3 = explode(".",$pageValues['data']['centerBanner']['ImagePath']);
		$pageValues["data"]["center_banner_name"] = $nameBanner3[0];
		/*********************************************************************/		
		$pageValues["page"] = $this->sPage->getPage(52, LANGUAGE_VIETNAMESE);
		$pageValues["news"]["hot"] = $this->sNews->getNewsHotList(LANGUAGE_VIETNAMESE, 0, HOMEPAGE_TOTAL_NEWS_PER_PAGE);
		
		$this->uiVar["pageValues"] = $pageValues;

		$smarty = Zend_Registry::get("SMARTY");
		$smarty->assign("uiVar", $this->uiVar);
		$smarty->display("about_privacy.htm");
	}
	
	public function contactAction()
	{
		$pageValues = array();
		$pageValues["error"] = SError::setError(0, "");
		
		/*********************************************************************/
		$sLogoBanner = new SLogobanner();		
		$pageValues["data"]["leftBanner"]=$bannerLeft = $sLogoBanner->getBanner(1);
		$nameBanner1 = explode(".",$pageValues['data']['leftBanner']['ImagePath']);
		$pageValues["data"]["left_banner_name"] = $nameBanner1[0];
		
		$pageValues["data"]["headerBanner"]=$bannerLeft = $sLogoBanner->getBanner(2);
		$nameBanner2 = explode(".",$pageValues['data']['headerBanner']['ImagePath']);
		$pageValues["data"]["header_banner_name"] = $nameBanner2[0];
		
		
		$pageValues["data"]["centerBanner"]=$bannerLeft = $sLogoBanner->getBanner(3);
		$nameBanner3 = explode(".",$pageValues['data']['centerBanner']['ImagePath']);
		$pageValues["data"]["center_banner_name"] = $nameBanner3[0];
		/*********************************************************************/		
		$pageValues["html"]["title"] = WEBSITE_TITLE;
		$pageValues["data"]["selectedMenu"] = "about";
		$pageValues["data"]["selectedSubMenu"] = "contact";
		
		if ($this->getRequest()->isPost())
		{
			$language = (int)trim($this->_getParam("lang"));
			if ($language == 0)
				$language = 1;
			$pageValues["data"]["lang"] = $language;
			$pageValues["data"]["company"] = $this->_getParam("company");
			$pageValues["data"]["sender"] = $this->_getParam("sender");
			$pageValues["data"]["position"] = $this->_getParam("position");
			$pageValues["data"]["address"] = $this->_getParam("address");
			$pageValues["data"]["phone"] = $this->_getParam("phone");
			$pageValues["data"]["fax"] = $this->_getParam("fax");
			$pageValues["data"]["email"] = $this->_getParam("email");
			$pageValues["data"]["subject"] = $this->_getParam("subject");
			$pageValues["data"]["content"] = $this->_getParam("content");
			
			if ((empty($pageValues["data"]["sender"])) || (empty($pageValues["data"]["email"])) || (empty($pageValues["data"]["subject"])) || (empty($pageValues["data"]["content"])))
			{
				$pageValues["error"]["code"] = 1;
				if ($pageValues["data"]["lang"] == 1)
					$pageValues["error"]["message"] .= "- Vui lòng nhập các thông tin bắt buộc có dấu *. <br />";
				else if ($pageValues["data"]["lang"] == 3)
					$pageValues["error"]["message"] .= "- 请检查有（*）的信息是否填写完整<br />";
			}
			
			if ($pageValues["error"]["code"] == 0)
			{
				$pageValues["data"]["ip"] = $this->_getClientIp();
				$this->uiVar["pageValues"] = $pageValues;
				$smarty = Zend_Registry::get("SMARTY");
				$smarty->assign("uiVar", $this->uiVar);
				$emailBody = $smarty->fetch("about_contact_email.htm");
				// Gởi email thông tin kích hoạt
				$smtp = Zend_Registry::get("SMTP");
				$mail = new Zend_Mail("UTF-8");
				$mail->setFrom(MAIL_FROM, MAIL_FROM_NAME);
				$mail->addTo(MAIL_CONTACT_EMAIL);
				$mail->setSubject("Thong tin lien he tu website");
				$mail->setBodyHtml($emailBody);
				$mail->send($smtp);
				
				$pageValues["error"]["code"] = 2;
				if ($language == 1)
					$pageValues["error"]["message"] = "Thông tin liên hệ của quý khách đã được gởi đến cho chúng tôi. Chúng tôi sẽ liên lạc với quý khách trong thời gian sớm nhất.<br />";
				else if ($language == 3)
					$pageValues["error"]["message"] = "您的意见已成功发送。我们会在最短时间内回复。谢谢。<br />";
				$pageValues["data"]["company"] = "";
				$pageValues["data"]["sender"] = "";
				$pageValues["data"]["position"] = "";
				$pageValues["data"]["address"] = "";
				$pageValues["data"]["phone"] = "";
				$pageValues["data"]["fax"] = "";
				$pageValues["data"]["email"] = "";
				$pageValues["data"]["subject"] = "";
				$pageValues["data"]["content"] = "";
			}
		}
		else
		{
			$language = (int)trim($this->_getParam("lang"));
			if ($language == 0)
				$language = 1;
			$pageValues["data"]["lang"] = $language;
		}
		
		$pageValues["news"]["hot"] = $this->sNews->getNewsHotList($language, 0, HOMEPAGE_TOTAL_NEWS_PER_PAGE);
		$this->uiVar["pageValues"] = $pageValues;

		$smarty = Zend_Registry::get("SMARTY");
		$smarty->assign("uiVar", $this->uiVar);
		$smarty->display("about_contact_" . $language . ".htm");
	}
	
	private function _getClientIp()
	{
		return $_SERVER["REMOTE_ADDR"];
	}
	
	
}
?>